<?php

namespace App\Http\Controllers;

use App\User;
use Illuminate\Support\Facades\Session;

class LoginController extends Controller
{
	/**
	 * 登录验证
	 *
	 * @return array
	 */
    public function auth(){
        $email = trim($_POST['email']);
		$user = User::get_user_by_email($email);
		if($user){
			$password = User::encrypt_password(trim($_POST['password']), $user['salt_word']);
			if($password == $user['password']){
				$user_info = User::get_user_by_id($user['user_id']);
				$this->buildSession($user_info);
				return $this->successResponse();
			}else{
				return $this->failResponse(trans('login_fail'));
			}
		}else{
			return $this->failResponse(trans('illegal_user'));
		}
    }
}
